<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'basic';
$return=array();
if($_RQ['op']=='basic'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if($postdata['isvideoshop']){
			$install = check_permission('jy_commission');
			if(!$install){
				exi('未安装分销客插件,不支持带商品！','error');
			}
		}
		$this->plugin_setting('basic',$postdata);
		//以公众号uniacid生成文件夹
		$dir = iconv("UTF-8", "GBK", ROOT_D.'/addons/jy_vote/cert/'.$_SESSION['uniacid']);
			if (!file_exists($dir)){
				mkdir ($dir,0777,true);
			  //  echo '创建文件夹成功';
			} else {
			  //  echo '需创建的文件夹已经存在';
			}
		$id=intval($post['id']);
		$data=array();
		//上传cert证书
		if($postdata['cert']&&$postdata['key']){
			
			$certfilename=pdo_getcolumn('core_attachment',array('attachment'=>$postdata['cert']),'title');
			$keyfilename=pdo_getcolumn('core_attachment',array('attachment'=>$postdata['key']),'title');
			
			$certfile_data=cfc('files')->source_read($postdata['cert']);
			$keyfile_data=cfc('files')->source_read($postdata['key']);
			
			file_put_contents(ROOT_D.'/addons/jy_vote/cert/'.$_SESSION['uniacid'].'/'.$certfilename.'.pem',$certfile_data);
			file_put_contents(ROOT_D.'/addons/jy_vote/cert/'.$_SESSION['uniacid'].'/'.$keyfilename.'.pem',$keyfile_data);
			
			//exi('认证文件上传成功','error');
		}

		exi('设置成功');
	}
	$footernav =array(
		array('title'=>'首页','icon'=>'icon-shouye','action'=>'jy_vote/index/'),
		array('title'=>'作品','icon'=>'icon-map','action'=>'jy_vote/o_list/'),
		array('title'=>'我的','icon'=>'icon-wo1','action'=>'jy_vote/home/'),
	);
	$hdps =array(
		array('title'=>'幻灯片','picurl'=>'../addons/jy_vote/resource/img/hdp01.jpg'),
	);
	$plugins =$this->plugins();
	$return['item']=$this->plugin_setting('basic');
	$return['item']['hdps']=$return['item']['hdps']?$return['item']['hdps']:$hdps;
	$return['item']['getredtext']=$return['item']['getredtext'] ? $return['item']['getredtext'] : '您收到一个好友的鼓励红包，请到“xxx”公众号领取哦!';
	$return['item']['setredtext']=$return['item']['setredtext'] ? $return['item']['setredtext'] : '您已成功发送一个红包!';
	$return['item']['footernav']=$return['item']['footernav']?$return['item']['footernav']:$footernav;
	$return['item']['plugins']=$return['item']['plugins']?$return['item']['plugins']:$plugins[1]['list'];
	$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'tabs'=>$tabs,
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'应用标题','name'=>'title','help'=>'建议18个字以内！'),
					array('type'=>'text','title'=>'描述','name'=>'desc','help'=>'建议68个字以内！'),
					array('type'=>'image','title'=>'网站logo','name'=>'logo','help'=>'建议尺寸：高68px*宽120px'),
					array('type'=>'string','title'=>'限制发布作品总数','name'=>'maxfabu','help'=>'为零，留空，则不限制！'),
					array('type'=>'switch','title'=>'是否开启作品审核','name'=>'needsh','help'=>'不开启则作品无需审核！'),
					array('type'=>'switch','title'=>'红包人工审核','name'=>'isconfirm','help'=>'不开启则红包自动发送给发布者'),
					array('type'=>'choose','title'=>'管理员UID','name'=>'adminuid','op'=>'get_member','choose_title'=>'选择会员','help'=>'便于接收平台高级消息！'),
					array('type'=>'radio','title'=>'首页排序规则','name'=>'paixu','options'=>'paixus','help'=>'设置首页排序规则：默认按投票数倒序'),
					array('type'=>'switch','title'=>'开启线上/线下投票模式','name'=>'is_downline'),
					array('type'=>'switch','title'=>'显示作品名称','name'=>'show_otitle','help'=>'默认显示选手名称！'),
					array('type'=>'string','title'=>'分享标题','name'=>'share_title'),
					array('type'=>'string','title'=>'分享描述','name'=>'share_desc'),
					array('type'=>'image','title'=>'分享图片','name'=>'share_image','help'=>'建议尺寸：高320px*宽640px'),
					array('type'=>'switch','title'=>'开启显示关注？','name'=>'needfollow','isradio'=>1),
					array('type'=>'string','title'=>'加关注标题','name'=>'followtitle'),
					array('type'=>'string','title'=>'加关注描述','name'=>'followdesc'),
					array('type'=>'image','title'=>'加关注二维码','name'=>'ewm'),
					array('type'=>'string','title'=>'TCP','name'=>'tcp'),
					array('type'=>'switch','title'=>'是否关闭海报','name'=>'noposter','help'=>'必须启用了超级海报插件，才有效！'),
					array('type'=>'switch','title'=>'是否支持带商品','name'=>'isvideoshop','help'=>'开启了带商品，参赛作品支持添加商品。'),
				)
			),
			array(
				'title'=>'vip收费设置',
				'list'=>array(
					array('type'=>'switch','title'=>'是否关闭VIP功能？','name'=>'no_vip','help'=>'关闭VIP功能，不再显示购买VIP'),
					array('type'=>'switch','title'=>'免费会员不能领红包？','name'=>'isfee_hongbao','help'=>'开启后，免费会员发布的作品，没有领红包功能！'),
					array('type'=>'string','title'=>'月费','name'=>'mfee'),
					array('type'=>'string','title'=>'月费原价','name'=>'mfee0'),
					array('type'=>'string','title'=>'季费','name'=>'jfee'),
					array('type'=>'string','title'=>'季费原价','name'=>'jfee0'),
					array('type'=>'string','title'=>'年费','name'=>'yfee'),
					array('type'=>'string','title'=>'年费原价','name'=>'yfee0'),
					array('type'=>'image','title'=>'充值会员页面背景图','name'=>'vipbg','help'=>'建议尺寸：高360px*宽640px'),
				)
			),
			array(
				'title'=>'幻灯片',
					'list'=>array(
						array(
							'type'=>'array',
							'name'=>'hdps',
							'add_tip'=>'添加一个幻灯片',
								'list'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片'),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								),
								'details'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片','help'=>'建议尺寸：高360px*宽640px'),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								)
						)
					)
			),
			array(
				'title'=>'板块导航',
					'list'=>array(
									array('type'=>'array','name'=>'bankuai','add_tip'=>'添加一个板块导航',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'image','name'=>'img','title'=>'导航图片'),
										array('type'=>'string','name'=>'action','title'=>'导航链接'),							
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'image','name'=>'img','title'=>'导航图片'),							
										array('type'=>'link','from'=>'action','name'=>'action','title'=>'导航链接'),
									)
								),
					)
			),
			array(
				'title'=>'底部导航',
					'list'=>array(
									array('type'=>'array','name'=>'footernav','add_tip'=>'添加一个底部导航',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标'),
										array('type'=>'string','name'=>'action','from'=>'action','title'=>'导航链接'),							
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标'),							
										array('type'=>'link','name'=>'action','from'=>'action','title'=>'导航链接'),
									)
								),
					)
			),
			array(
				'title'=>'消息模版',
				'list'=>array(
					array('type'=>'switch','title'=>'是否开启模板消息','name'=>'istpl','help'=>'关闭则发送客服消息！(温馨提示：客服消息48小时内，客户必须跟公众号存在交互行为，比如发送消息给公众号，否则不推送信息！)'),
					array('type'=>'string','title'=>'收红包消息模版','name'=>'getred','help'=>'IT科技行业在模板库选择行业IT科技－互联网|电子商务，搜索“排号提醒通知”编号为OPENTM205984119的模板'),
					array('type'=>'string','title'=>'收到红包的消息内容','name'=>'getredtext','help'=>'自定义收到红包的消息提醒！'),
					array('type'=>'string','title'=>'发红包消息模版','name'=>'setred','help'=>'IT科技行业在模板库选择行业IT科技－互联网|电子商务，搜索“服务状态提醒”编号为OPENTM401684051的模板'),
					array('type'=>'string','title'=>'发到红包的消息内容','name'=>'setredtext','help'=>'自定义发红包的消息提醒！'),
					array('type'=>'string','title'=>'购买VIP消息模版','name'=>'buyvip','help'=>'IT科技行业在模板库选择行业IT科技－互联网|电子商务，搜索“服务状态提醒”编号为OPENTM401684051的模板'),
					array('type'=>'string','title'=>'店员-购买VIP消息模版','name'=>'getvip','help'=>'IT科技行业在模板库选择行业IT科技－互联网|电子商务，搜索“订单状态提醒”编号为OPENTM206848054的模板'),					
				)
			),
			array(
				'title'=>'支付参数设置',
				'list'=>array(
					array('type'=>'string','title'=>'身份标识(AppId)','name'=>'appid'),
					array('type'=>'string','title'=>'微信支付商户号(MchId)','name'=>'mchid'),
					array('type'=>'string','title'=>'商户支付密钥(API密钥)','name'=>'apikey'),
					array('type'=>'upfile','title'=>'cert证书','name'=>'cert','help'=>'从商户平台上下载支付证书, 解压并取得其中的 apiclient_cert.pem，并在此处上传。'),
					array('type'=>'upfile','title'=>'key证书','name'=>'key','help'=>'从商户平台上下载支付证书, 解压并取得其中的 apiclient_key.pem，并在此处上传。'),
				
				)
			),
			array(
				'title'=>'页面排版',
				'list'=>array(
					array('type'=>'switch','title'=>'是否关闭首页幻灯片？','name'=>'no_hdp'),
					array('type'=>'switch','title'=>'是否关闭首页收藏足迹？','name'=>'no_zuji'),
					array('type'=>'switch','title'=>'是否关闭首页分类？','name'=>'no_group'),
					array('type'=>'switch','title'=>'是否关闭首页公告？','name'=>'no_notice'),
					array('type'=>'switch','title'=>'是否关闭首页活动？','name'=>'no_reply'),
				)
			),
			array(
				'title'=>'页面UI',
				'list'=>array(
					array('type'=>'colorpicker','title'=>'项目顶部颜色','name'=>'r_color','help'=>'自定义系统颜色系，默认： red'),
					array('type'=>'image','title'=>'会员顶部图片','name'=>'h_img','help'=>'建议尺寸：高360px*宽640px'),
					array('type'=>'colorpicker','title'=>'会员顶部颜色','name'=>'h_color','help'=>'自定义系统颜色系，默认： red'),
					array('type'=>'image','title'=>'作品列表顶部图片','name'=>'o_img','help'=>'建议尺寸：高360px*宽640px'),
					array('type'=>'colorpicker','title'=>'作品列表顶部颜色','name'=>'o_color','help'=>'自定义系统颜色系，默认： red'),
					array('type'=>'image','title'=>'发红包弹窗背景图','name'=>'o_hongbao','help'=>'发红包弹窗背景图，建议尺寸：高520px*宽360px'),
				)
			)
		),
	);
	$return['paixus']=array('按票数','按点赞数');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='get_member'){
	//会员列表
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$fields=array('username','nickname','mobile');
	if($_RQ['find']){
		$field=in_array($_RQ['field'],$fields)?$_RQ['field']:'nickname';
		$params[$field.' like']='%'.$_RQ['find'].'%';
		$return['params']['find']=$_RQ['find'];
		$return['params']['field']=$field;
	}
	$list=pdo_getslice('core_members',$params,array($pindex,$psize),$total,array('id','username','mobile','nickname','avatar'),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['avatar'] = $item['avatar']?$item['avatar']:'../addons/jy_paimai/resource/images/userlogo.jpg';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员列表'),
		),
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
		    array('name'=>'id','title'=>'会员id','type'=>'string'),
			array('name'=>'username','title'=>'会员账号','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'id','title_field'=>'nickname','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'find','select_name'=>'field','select_title'=>'筛选','is_radio'=>true,'options'=>'fields'),
	);
	$return['fields']=array(
		'username'=>'会员账号',
		'nickname'=>'会员昵称',
		'mobile'=>'会员手机',
	);
	exi($return);
}


